package com.wd.jetpack.util;


public class CommonMessageSource {
    public static MessageResourceBundles resourceBundles = null;

    public static String getMessage(String key, Object[] args, String defaultValue) {
        String value = getMessage(key);
        if (value == null) {
            return defaultValue;
        } else {
            return String.format(value, args);
        }
    }


    public static String getMessage(String key, String defaultValue) {
        String value = getMessage(key);
        if (value == null) {
            return defaultValue;
        } else {
            return value;
        }
    }

    public static String getMessage(String key) {
        init();
        return resourceBundles.getMessage(key);
    }

    private static void init() {
        if (resourceBundles == null) {
            resourceBundles = new MessageResourceBundles(new String[]{"common-messages"});
        }
    }
}
